/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.courier.model;

import com.sun.courier.entity.Courier;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author HONG QUAN
 */
public class CourierModel extends AbstractTableModel {

    Vector columnNames = new Vector();
    public Vector data = new Vector();

    public Vector delCourierId = new Vector();
    public Vector insCourierId = new Vector();
    public Vector updCourierId = new Vector();

    String[][] inData;

    public CourierModel(ArrayList<Courier> lst) {
        String empty = "";
        inData = new String[lst.size()][10];
        for (int i = 0; i < lst.size(); i++) {
            inData[i][0] = Integer.toString(lst.get(i).getCourierId());
            inData[i][1] = lst.get(i).getCourierName();
            inData[i][2] = lst.get(i).getCustomerName();
            inData[i][3] = lst.get(i).getPhone();
            inData[i][4] = lst.get(i).getStatus();
            inData[i][5] = lst.get(i).getWeight();
            inData[i][6] = lst.get(i).getDepartLocation();
            inData[i][7] = lst.get(i).getDestination();
            inData[i][8] = lst.get(i).getDistance();
            inData[i][9] = empty;
        }
    }

    @Override
    public int getRowCount() {
        return inData.length;
    }

    @Override
    public int getColumnCount() {
        return 10;
    }

    @Override
    public Object getValueAt(int row, int col) {
        return inData[row][col];
    }

    @Override
    public void setValueAt(Object value, int row, int col) {
        inData[row][col] = (String) value;
        fireTableCellUpdated(row, col);
    }
    public void updateRow(int index, String[] values) {
        for (int i = 0; i < values.length; i++) {
            setValueAt(values[i], index, i);
        }
    }
//    @Override
//    public Class<?> getColumnClass(int c) {
//        return getValueAt(0, c).getClass();
//    }
//
//    @Override
//    public String getColumnName(int col) {
//        return (String) columnNames.get(col);
//    }
}
